package com.jihong.util;

import org.apache.ibatis.mapping.ParameterMapping;

import java.util.ArrayList;
import java.util.List;

public class ParamMappingHandler {

    private List<ParameterMapping> parameterMappingList;
    List<ParameterMapping> encryptParameterMapping;
    private int paramIndex;


    public ParamMappingHandler(List<ParameterMapping> parameterMappingList) {
        this.parameterMappingList = parameterMappingList;
        encryptParameterMapping = new ArrayList<>();
    }

    public void addEncryptParameterMapping(ParameterMapping parameterMapping){
        encryptParameterMapping.add(parameterMapping);
    }

    public void addAllEncryptParameterMapping(List<ParameterMapping> parameterMappingList){
        if (parameterMappingList != null && parameterMappingList.size() > 0)
            encryptParameterMapping.addAll(parameterMappingList);
    }


    public ParameterMapping getOneParameterMapping() {
        List<ParameterMapping> parameterMappingList = getParameterMappingList(1);
        return parameterMappingList.get(0);
    }


    public List<ParameterMapping> getParameterMappingList(int count) {
        List<ParameterMapping> list = new ArrayList<>();
        for (int i = 0; i < count; i++) {
            list.add(parameterMappingList.get(paramIndex++));
        }
        return list;
    }
}